package br.com.mundodaprata.store.data;

import br.com.center.loja.data.jdbc.CityRepositoryJDBC;
import br.com.center.loja.data.jdbc.ClientRepositoryJDBC;
import br.com.center.loja.data.jdbc.EmployeeRepositoryJDBC;
import br.com.center.loja.data.jdbc.NeighborhoodRepositoryJDBC;
import br.com.center.loja.data.jdbc.OrderItemRepositoryJDBC;
import br.com.center.loja.data.jdbc.OrderRepositoryJDBC;
import br.com.center.loja.data.jdbc.ProductRepositoryJDBC;
import br.com.center.loja.data.jdbc.StreetRepositoryJDBC;
import br.com.center.loja.data.jdbc.UserRepositoryJDBC;
import br.com.center.loja.model.City;
import br.com.center.loja.model.Client;
import br.com.center.loja.model.Employee;
import br.com.center.loja.model.Neighborhood;
import br.com.center.loja.model.Order;
import br.com.center.loja.model.OrderItem;
import br.com.center.loja.model.Product;
import br.com.center.loja.model.Street;
import br.com.center.loja.model.User;

public class RepositoryFactoryJDBC {
   @SuppressWarnings("unchecked")
   public static <T> Repository<T> create(Class<T> type){
      if(type.isAssignableFrom(City.class)){
         return (Repository<T>) new CityRepositoryJDBC();
      }
      
      if(type.isAssignableFrom(Neighborhood.class)){
         return (Repository<T>) new NeighborhoodRepositoryJDBC();
      }
      
      if ( type.isAssignableFrom(Street.class)){
         return (Repository<T>) new StreetRepositoryJDBC();
      }
      
      if ( type.isAssignableFrom(Client.class)){
         return (Repository<T>) new ClientRepositoryJDBC();
      }

      if ( type.isAssignableFrom(Product.class)){
         return (Repository<T>) new ProductRepositoryJDBC();
      }
      
      if ( type.isAssignableFrom(OrderItem.class)){
         return (Repository<T>) new OrderItemRepositoryJDBC();
      }

      if ( type.isAssignableFrom(Order.class)){
         return (Repository<T>) new OrderRepositoryJDBC();
      }
      
      if ( type.isAssignableFrom(Employee.class)){
         return (Repository<T>) new EmployeeRepositoryJDBC();
      }

      if ( type.isAssignableFrom(User.class)){
         return (Repository<T>) new UserRepositoryJDBC();
      }
      
      return null;
   }
}